#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n, q, ma = 0;
    cin >> n;
    vector<int> arr(n + 1), dp(n + 1);
    for (int i = 1; i <= n; i++) cin >> arr[i];
    dp[1] = 0, ma = arr[1];
    for (int i = 2; i <= n; i++)
    {
        if (arr[i] >= ma) dp[i] = ma, ma = arr[i];
        else if (arr[i] > dp[i - 1]) dp[i] = arr[i];
        else dp[i] = dp[i - 1];
    }
    cin >> q;
    while (q--)
    {
        int x;
        cin >> x;
        cout << dp[x] << endl;
    }
}